package com.dev.op.config;

import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 专门用于过滤查询问题id的请求，减少对 持久层数据库压力
 */
@Configuration
public class BloomFilterProblemConfig {
    @Autowired
    private RedissonClient redissonClient;

    @Bean
    public RBloomFilter<String> problemIdBloomFilter() {
        // 创建
        RBloomFilter<String> bloomFilter = redissonClient.getBloomFilter("problemIdBloomFilter");
        // 预计存储 10000 个元素，误判率 3%
        bloomFilter.tryInit(10000, 0.03);
        return bloomFilter;
    }
}
